package org.jks.model;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.GenericGenerator;

import com.google.gson.annotations.Expose;

@Entity
@Table(name = "Role")
public class Role {
	@Id
	@GeneratedValue(generator = "increment")
	@GenericGenerator(name = "increment", strategy = "increment")
	@Expose
	private long Id;
	@Column(length = 64, nullable = false, unique = true)
	@Expose
	private String Name;
	@Column(length = 1024, nullable = false)
	@Expose
	private String Desp;
	@ManyToMany(cascade = { CascadeType.PERSIST, CascadeType.MERGE }, fetch = FetchType.LAZY, mappedBy = "roles")
	private Set<User> users = new HashSet<User>();
	@OneToMany(fetch = FetchType.LAZY, cascade={CascadeType.ALL}, mappedBy="Role")
	@Expose
	private List<RolePrivilege> privileges = new ArrayList<RolePrivilege>();

	public long getId() {
		return Id;
	}

	public void setId(long id) {
		Id = id;
	}

	public String getName() {
		return Name;
	}

	public void setName(String name) {
		Name = name;
	}

	public String getDesp() {
		return Desp;
	}

	public void setDesp(String desp) {
		Desp = desp;
	}

	public Set<User> getUsers() {
		return users;
	}

	public void setUsers(Set<User> users) {
		this.users = users;
	}

	public List<RolePrivilege> getPrivileges() {
		return privileges;
	}

	public void setPrivileges(List<RolePrivilege> privileges) {
		this.privileges = privileges;
	}

	@Override
	public String toString() {
		return "Role [Id=" + Id + ", Name=" + Name + ", Desp=" + Desp
				+ ", users=" + users + ", privileges=" + privileges + "]";
	}

}
